﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LabTask1Sharp
{
    public partial class Main : Form
    {
        private Graph graph = new Graph();
        private FilenameInput FilenameInput = new FilenameInput();
        private HelpForm HelpForm = new HelpForm();

        public Main()
        {
            InitializeComponent();
            graph.ReadLinks("roads.csv");
            graph.ReadNodes("locations.csv");
        }

        private void Main_Paint(object sender, PaintEventArgs e)
        {
            graph.DrawMap(this.CreateGraphics());
        }

        private void Main_MouseClick(object sender, MouseEventArgs e)
        {
            if (graph.CheckIfAnyNodeClicked(e.X, e.Y, e.Button))
                this.Invalidate();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void loadLocationsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FilenameInput.Text = "Load Nodes From";
            if (FilenameInput.ShowDialog() == DialogResult.OK)
            {
                graph.ReadNodes(FilenameInput.Input);
            }
        }

        private void loadLinksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FilenameInput.Text = "Load Links From";
            if (FilenameInput.ShowDialog() == DialogResult.OK)
            {
                graph.ReadLinks(FilenameInput.Input);
            }
        }

        private void iterativeDeepeningToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (graph.HasStartSelected && graph.HasEndSelected)
                graph.DrawPath(graph.IDDFSearch(), this.CreateGraphics(), Color.Orange);
        }

        private void bestFirstToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (graph.HasStartSelected && graph.HasEndSelected)
                graph.DrawPath(graph.GBFSearch(), this.CreateGraphics(), Color.Brown);
        }

        private void aToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (graph.HasStartSelected && graph.HasEndSelected)
                graph.DrawPath(graph.AStarSearch(), this.CreateGraphics(), Color.Red);
        }

        private void helpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HelpForm.Show();
        }

        private void Main_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F1)
                HelpForm.Show();
        }
    }
}
